const cloud = require('wx-server-sdk');
const tools = require('./utils/tools');

// 初始化 cloud
cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})

class Base {
    constructor() {
        this.tools = tools
        this.cloud = cloud
        this.dbBase = cloud.database()
    }
}

/**
 * Controller 基础类
 */
class BaseController extends Base {
    constructor() {
        super();
        this.name = 'Controller'
    }
    // 返回成功
    resSuccess(data) {
        return tools.resSuccess(data)
    }
    // 返回失败
    resError(message, code) {
        return tools.resError(message, code)
    }
    // 获取 openid
    getOpenid() {
        const wxContext = this.cloud.getWXContext()
        return wxContext.OPENID
    }
}

/**
 * Servers 基础类
 */
class BaseServers extends Base {
    constructor() {
        super();
        this.name = 'Servers'
    }
}

module.exports = {
    Base,
    BaseServers,
    BaseController
}